Accumulating Definitions

There are three steps required to handle a definition:

  1. Build an entry for the name so we can look it up later.
  2. Collect the scrap and save it in the table of scraps.
  3. Attach the scrap to the name.
We go through the same steps for both file names and macro names. @d Build output file definition @ Name *name = collect_file_name(); /* returns a pointer to the name entry */ int scrap = collect_scrap(); /* returns an index to the scrap */ @<Add scrap to...@> @

@d Build macro definition @ Name *name = collect_macro_name(); int scrap = collect_scrap(); @<Add scrap to...@> @

Since a file or macro may be defined by many scraps, we maintain them in a simple linked list. The list is actually built in reverse order, with each new definition being added to the head of the list. @d Add scrap to name's definition list @ Scrap_Node *def = (Scrap_Node *) arena_getmem(sizeof(Scrap_Node)); def->scrap = scrap; def->next = name->defs; name->defs = def; @